package com.yusheng.tr.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yusheng.domain.R;
import com.yusheng.tr.common.core.entity.system.SysNotice;
import com.yusheng.tr.common.core.page.PageParam;
import com.yusheng.tr.system.service.ISysNoticeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 公告 信息操作处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/notice")
@Tag(name = "公告 信息")
public class SysNoticeController {
    @Autowired
    private ISysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:notice:list')")
    @GetMapping("/list")
    public R<?> list(PageParam<SysNotice> notice) {
        PageInfo<SysNotice> page = PageHelper.startPage(
                        notice.getPageNum(), notice.getPageSize())
                .doSelectPageInfo(() -> noticeService.selectNoticeList(notice.getParam()));
        return R.ok(page);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping(value = "/{noticeId}")
    public R<?> getInfo(@PathVariable Long noticeId) {
        return R.ok(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:add')")
    //@Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@Validated @RequestBody SysNotice notice) {
        return R.ok(noticeService.insertNotice(notice));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
    //@Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@Validated @RequestBody SysNotice notice) {
        return R.ok(noticeService.updateNotice(notice));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:remove')")
   // @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public R<?> remove(@PathVariable Long[] noticeIds) {
        return R.ok(noticeService.deleteNoticeByIds(noticeIds));
    }
}
